package Util;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class FabricaConexao {
    private static final String driverConexao = "jdbc:firebirdsql";
    private static final String nomeBanco = "C:\\MANTERFRETE_BD.FDB";
    private static final String ip = "127.0.0.1";
    private static final String porta = "3050";
    private static final String user = "sysdba";
    private static final String senha = "masterkey";
    private static final String driverName = "org.firebirdsql.jdbc.FBDriver";
    
    private static Connection Conexao;

    public FabricaConexao(){
        Conexao = null;
        try{
            try {
                try {
                    Class.forName(driverName).newInstance();
                } catch (InstantiationException ex) {
                    Logger.getLogger(FabricaConexao.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(FabricaConexao.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(FabricaConexao.class.getName()).log(Level.SEVERE, null, ex);
            }
            String url = driverConexao + ":" + ip + "/" + porta + ":" + nomeBanco;
            Conexao = DriverManager.getConnection(url,user, senha);
            
        }catch(SQLException e){
            String erro = "Erro ao abrir a conexão: "+e.getMessage();
            JOptionPane.showMessageDialog(null,erro,"Mensagem de erro",0);
        }
    }

    public static Connection GetConexao(){
        if(Conexao==null){
            FabricaConexao ManterConexao = new FabricaConexao();
        }
        return Conexao;
    }

}
